package business.Impl;

import java.util.List;

import org.springframework.stereotype.Component;

import model.TNovelType;
import model.VNovel;
import business.basic.HibBaseDAOImpl;
import business.basic.iHibBaseDAO;
import business.dao.NovelDAO;
@Component("noveldao")
public class NovelDAOImpl implements NovelDAO {
	private iHibBaseDAO hdao = null;

	public NovelDAOImpl(){
		this.hdao = new HibBaseDAOImpl();
	}
	@Override
	public List<VNovel> getNovelList(String wherecondition, int page,
			int pageSize) {
		String hql = "from VNovel";
		if (wherecondition != null && !wherecondition.equals("")) {
			hql += wherecondition;
		}
		List<VNovel> list = hdao.selectByPage(hql, page, pageSize);
		return list;
	}

	@Override
	public int getNovelAmount(String wherecondition) {
		String hql = "select count(*) from VNovel";
		if (wherecondition != null && !wherecondition.equals("")) {
			hql += wherecondition;
		}
		int count = hdao.selectValue(hql);
		return count;
	}
	
	@Override
	public boolean passAuditStatus(int novelid) {
		String sql = "update T_Novel set auditstatus = 'True' where novelid = ?";
		Object[] para = {novelid};
		if (hdao.update(sql, para)) {
			return true;
		}else {
			return false;
		}
	}
	@Override
	public boolean notpassAuditStatus(int novelid) {
		String sql = "update T_Novel set auditstatus = 'False' where novelid = ?";
		Object[] para = {novelid};
		if (hdao.update(sql, para)) {
			return true;
		}else {
			return false;
		}
	}
	
	@Override
	public boolean passNovelStatus(int novelid) {
		String sql = "update T_Novel set novelstatus = 1 where novelid = ?";
		Object[] para = {novelid};
		if (hdao.update(sql, para)) {
			return true;
		}else {
			return false;
		}
	}
	
	@Override
	public boolean notpassNovelStatus(int novelid) {
		String sql = "update T_Novel set novelstatus = 2 where novelid = ?";
		Object[] para = {novelid};
		if (hdao.update(sql, para)) {
			return true;
		}else {
			return false;
		}
	}
	
	public static void main(String[] args) {
		NovelDAO ndao = new NovelDAOImpl();
		System.out.println(ndao.notpassNovelStatus(14));
	}
	@Override
	public List<TNovelType> getNovelTypeList() {
		String hql = "from TNovelType";
		return hdao.select(hql);
	}
	@Override
	public boolean modifyNovelType(int id, int novelid) {
		String sql = "update T_Novel set noveltype = ? where novelid = ?";
		Object[] para = {id,novelid};
		if (hdao.update(sql, para)) {
			return true;
		}else {
			return false;
		}
	}
}
